home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Arsenal / OS2 Arsenal v1.0 (Disc 1)(Arsenal Computer).ISO / os2_utl4 / times.cmd < prev    next >
OS/2 REXX Batch file  |  1995-06-02  |  4KB  |  127 lines

  1. /* Rexx utility to get connection times from TCPOS2.INI file
  2.  * These are the connection times recorded by the IBM Dial-Up for TCP/IP
  3.  * program,  SLIPPM.
  4.  *
  5.  * syntax:  IAKTIMES
  6.  *
  7.  * output:  a summary of the connection times as stored by SLIPPM listed
  8.  *          by connection identifier and totaled.
  9.  *
  10.  * Written by: Dan Douglas
  11.  *             dandoug@scruznet.com
  12.  *
  13.  * Feel free to use, distribute or modify as you see fit.  If you find it
  14.  * helpful, send me a postcard.
  15.  */
  16.  
  17. /* Added a few lines to save output to a file - 'cause I wanted it to
  18.  *
  19.  *  Steve McCrystal  
  20.  *  stevem@execpc.com 
  21.  *
  22.  * Thanks, Dan!
  23.  */
  24.  
  25. /* Save command name for use in messages */
  26. Parse upper source . . src '.CMD'
  27. src = substr(src, lastpos('\',src)+1)
  28. msghdr = '>>'src'>>'
  29.  
  30. /* Set field widths and NLS strings for formatting */
  31. al  = 10 /* application name length */
  32. sl  = 10 /* max digits in seconds string */
  33. hl  = 4  /* max digits in connect hours */
  34. dl  = 2  /* max ditits in connect days */
  35. day = 'day, ' /* singular day label */
  36. dys = 'days,' /* plural days label */
  37. ll  = al + sl + hl + dl + length(dys) + 21
  38.  
  39. err = 'ERROR:'
  40. all = 'ALL:'
  41. tck = 'TOTAL_CONNECT'  /* key for total connect seconds */
  42. etc = 'ETC'            /* ennvironment variable with path */
  43. fn  = 'TCPOS2.INI'     /* ini file name */
  44. env = 'OS2ENVIRONMENT' /* environment for OS/2 variables */
  45. logfile = 'totals.log'
  46. ts     = 'total'
  47. msgs.1 = 'OS/2 environment variable 'etc' must be set to 'fn' path.'
  48. msgs.2 = 'Error reading 'fn' applications.'
  49. msgs.3 = 'No applications with non-zero 'tck' time found.'
  50.  
  51. if stream(logfile,'C','QUERY EXISTS') = ""
  52. then nop
  53. else 'erase' logfile 
  54.  
  55. /* Get value of ETC environment variable and use it to build
  56.    full name TCPOS2.INI file */
  57. path = VALUE(etc,,env)
  58. if path = '' then do
  59.    say msghdr msgs.1
  60.    exit -1
  61. end  /* Do */
  62. ini_file = path"\"fn
  63.  
  64. /* Load utility function to read INI file */
  65. call RxFuncAdd 'SysIni', 'RexxUtil', 'SysIni'
  66.  
  67. /* Read all the applications in the INI file */
  68. if SysIni(ini_file,all,'Apps.') = err then do
  69.    say msghdr msgs.2
  70.    exit -2
  71. end  /* Do */
  72.  
  73. /* Find all the applications with a TOTAL_CONNECT key that has
  74.    a non-blank, non-zero value */
  75. total = 0
  76. Do i = 1 to Apps.0
  77.   l_ct = SysIni(ini_file,Apps.i,tck)
  78.   parse value l_ct with l_ct '00'x
  79.   if l_ct \= err & l_ct \= '' & l_ct \= 0 then do
  80.       call stream logfile,'C','OPEN READ'
  81.     say left(Apps.i,al) right(l_ct,sl) hms(l_ct)
  82.       call lineout logfile, left(Apps.i,al) right(l_ct,sl) hms(l_ct)
  83.      total = total + l_ct
  84.   end
  85. end
  86.  
  87. /* Put out summary lines */
  88. if total = 0 then do /* did we find what we wanted?*/
  89.     say msghdr msgs.3
  90.     call lineout logfile, msghdr msgs.3
  91.   exit -3
  92. end
  93. else do
  94.     say copies('-',ll)
  95.       call lineout logfile, copies('-',ll)
  96.     say left(ts,al) right(total,sl) hms(total)
  97.       call lineout logfile, left(ts,al) right(total,sl) hms(total)
  98.       call stream logfile,'C','CLOSE'
  99. end  /* Do */
  100.  
  101. exit 0
  102.  
  103. /* Subroutine to compute hours, minutes, seconds from seconds */
  104. HMS: procedure expose hl dl day dys
  105.  p_s = ARG(1)        /* single argument, number of seconds */
  106.  
  107.  hh  = p_s %  3600   /* number of whole hours */
  108.  m_s = p_s // 3600   /* leftover seconds from whole hours */
  109.  mm  = m_s %  60     /* number of whole minutes */
  110.  ss  = m_s // 60     /* leftover seconds from whole minutes */
  111.  
  112.  dd  = hh  %  24     /* whole days */
  113.  dh  = hh  // 24     /* leftover hours from whole days */
  114.  
  115.  ms  = right(mm,2,'0')':'right(ss,2,'0')  /* min/sec part of display */
  116.  
  117.  hs = right(hh,hl)':'ms  /* hourly result */
  118.  
  119.  if dd > 1 then  /* more than one day? */
  120.   ds = '('right(dd,dl)' 'dys' 'right(dh,2,0)':'ms')'
  121.  else if dd = 1 then /* only one day, leave off 's' in display */
  122.   ds = '('right(dd,dl)' 'day' 'right(dh,2,0)':'ms')'
  123.  else /* just hours...left day part blank */
  124.   ds = '('copies(' ',dl+2+length(dys))right(dh,2,0)':'ms')'
  125.  
  126. return hs ds
  127.